package com.hzy.fivepalace.wx.controller.api;

import com.hzy.fivepalace.common.type.HtmlTypeEnums;
import com.hzy.fivepalace.common.util.ResponseUtil;
import com.hzy.fivepalace.db.service.DtsHtmlService;
import com.hzy.fivepalace.db.service.DtsRegionService;
import com.hzy.fivepalace.db.service.DtsSinceSiteService;
import com.hzy.fivepalace.db.vo.wx.WxFeedbackVo;
import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxCommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;


/**
 * 通用服务
 */
@RestController
@RequestMapping("/wx/common")
@Validated
@Api(tags = "通用服务")
public class WxCommonController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(WxCommonController.class);


    @Autowired
    private DtsRegionService regionService;

    @Autowired
    private DtsHtmlService htmlService;

    @Autowired
    private WxCommonService commonService;

    @Resource
    private DtsSinceSiteService sinceSiteService;

    /**
     * 获取自提点信息
     *
     * @return
     */
    @GetMapping("/getSinceSiteInfo")
    @ApiOperation(value = "获取自提点信息")
    public Object getSinceSiteInfo() {
        return sinceSiteService.getSinceSiteInfo();
    }


    /**
     * 获取静态页面内容
     *
     * @param type 静态页面类型
     * @return
     */
    @GetMapping("getHtml")
    @ApiOperation(value = "获取静态页面内容")
    public Object getHtml(@ApiParam(value = "类型") @NotNull Integer type) {

        HtmlTypeEnums htmlTypeEnums = HtmlTypeEnums.getEnum(type);
        if (null == htmlTypeEnums) {
            return ResponseUtil.badArgument("查询类型不存在");
        }
        return ResponseUtil.ok(htmlService.getHtmlContentByType(type));
    }


    /**
     * 所有的区域列表
     *
     * @return
     */
    @GetMapping("getAllList")
    @ApiOperation(value = "所有的区域列表")
    public Object getGruopTree() {
        return ResponseUtil.ok(regionService.getAllList());
    }


    /**
     * 添加意见反馈
     *
     * @param userId
     * @param feedback
     * @return
     */
    @PostMapping("submitFeedback")
    @ApiOperation(value = "添加意见反馈")
    public Object submitFeedback(@LoginUser   @ApiParam(hidden = true) Integer userId, @RequestBody WxFeedbackVo feedback) {

        return commonService.submitFeedback(userId, feedback);
    }

}
